package com.atguigu.juc.day02;

import java.util.concurrent.CountDownLatch;

/**
 * @author atguigu-mqx
 */
public class CountDownLatchDemo {

    //  主入口：
    public static void main(String[] args) throws InterruptedException {
        //  6个同学陆续离开教室后值班同学才可以关门
        CountDownLatch countDownLatch = new CountDownLatch(6);

        //  创建6个线程，让其离开教室！
        for (int i = 0; i < 6; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"离开教室");
                //  较少计数
                countDownLatch.countDown();
            },String.valueOf(i)).start();
        }
        //  如果计数器不为0的时候，需要等待！
        countDownLatch.await();

        System.out.println("值班同学关门!");

    }
}
